var arr = [5, 9, 3, 1, 2, 8, 4, 7, 6]
//冒泡排序
for (let i = 0; i < arr.length; i++) {
    for (let j = i + 1; j < arr.length; j++) {
        if (arr[j] < arr[i]) {
            var t = arr[i]
            arr[i] = arr[j]
            arr[j] = t
        }
    }
}
console.log(arr);
//选择排序
for (let i = 0; i < arr.length; i++) {
    var minIndex = i
    for (let j = i; j < arr.length; j++) {
        if (arr[j] < arr[minIndex]) {
            minIndex = j
        }
    }
    var t = arr[i]
    arr[i] = arr[minIndex]
    arr[minIndex] = t
}
console.log(arr);
//插入排序
for (let i = 1; i < arr.length; i++) {
    var behind = arr[i]
    var beforeIndex = i - 1
    while (behind < arr[beforeIndex] && beforeIndex >= 0) {
        arr[beforeIndex + 1] = arr[beforeIndex]
        beforeIndex--
    }
    arr[beforeIndex + 1] = behind
}
console.log(arr);
//快速排序
function loop(arr) {
    if (arr.length <= 1) {
        return arr
    }
    var mid = Math.ceil(arr.length / 2)
    var t = arr.splice(mid, 1)
    var left = []
    var right = []
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < t) {
            left.push(arr[i])
        } else {
            right.push(arr[i])
        }
    }
    return loop(left).concat(t).concat(loop(right))
}
console.log(loop(arr));